package com.example.baserecyclerviewadapterdemo.adapter.diffUtil;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.baserecyclerviewadapterdemo.R;
import com.example.baserecyclerviewadapterdemo.entity.DiffUtilEntity;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class DiffUtilAdapter extends BaseQuickAdapter<DiffUtilEntity, BaseViewHolder> {

    public static final int ITEM_0_PAYLOAD = 901;
    public DiffUtilAdapter(@Nullable List<DiffUtilEntity> data) {
        super(R.layout.layout_animation, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, DiffUtilEntity item) {
        holder.setText(R.id.tweetName, item.getTitle())
                .setText(R.id.tweetText, item.getContent())
                .setText(R.id.tweetDate, item.getDate());
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, DiffUtilEntity item, @NotNull List<?> payloads) {
        for (Object payload : payloads) {
            int p = (int) payload;
            if (p == ITEM_0_PAYLOAD) {
                holder.setText(R.id.tweetName, item.getTitle())
                        .setText(R.id.tweetText, item.getContent());
            }
        }
    }
}
